﻿using Growatt.OutPutDataProcess;
using Growatt.OutPutDataProcess.DataSetResolve;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Growatt.WaveData.DataSetResolve
{
    public  class CreatVariableAddress
    {
        public CreatVariableAddress(string file,InitialData initialData)
        {
      
            if (!string.IsNullOrEmpty(file))
            {
                this.initialData1 = initialData;
                fileSourse = file;
                if (fileSourse.EndsWith(".out"))
                {
                    var strContent = ($"ofd6x -g --dwarf_display=dinfo App.out >outPut.txt");//将所有文件转换成excel文件并添加样式
                    callofd6x(strContent);
                    var strings = LoadFilelistString(Path.Combine($"{AppDomain.CurrentDomain.BaseDirectory}", "Parser", "outPut.txt")).ToList();
                    bool falg = false;
                    bool falg1 = false;
                    List<(string, int, string)> ints = new List<(string, int, string)>();

                    Func<string, bool> func = (st
                        ) =>
                    {
                        if (st.Contains(typeof(DW_TAG_base_type).Name) || st.Contains(typeof(DW_TAG_pointer_type).Name) || st.Contains(typeof(DW_TAG_member).Name) || st.Contains(typeof(DW_TAG_typedef).Name) || st.Contains(typeof(DW_TAG_structure_type).Name) || st.Contains(typeof(DW_TAG_array_type).Name) || st.Contains(typeof(DW_TAG_variable).Name) || st.Contains("DW_AT_name") || st.Contains("DW_AT_name") || st.Contains("DW_AT_type") || st.Contains("DW_AT_TI_symbol_name") || st.Contains("DW_AT_byte_size") || st.Contains("DW_AT_bit_size") || st.Contains("DW_AT_data_member_location") || st.Contains("DW_TAG_union_type") || st.Contains("DW_TAG_enumeration_type") || st.Contains("DW_TAG_enumerator") || st.Contains("DW_AT_const_value") || st.Contains("DW_TAG_TI_far_type") || st.Contains("DW_TAG_volatile_type"))
                        {
                            return true;
                        }
                        else return false;
                    };
                    for (int i = 0; i < strings.Count; i++)
                    {

                        var item = strings[i];
                        //if (falg1)
                        {
                            var stringsSplite = item.Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();
                            if (stringsSplite.Count >= 0 && stringsSplite.Count >= 3)
                                if (stringsSplite[2].Contains("DW_TAG_"))
                                {
                                    valuesTotal.Add((stringsSplite[0], stringsSplite[2]));
                                    if (!stringsSplite[2].Equals("DW_TAG_member") && !stringsSplite[2].Equals("DW_TAG_enumerator"))
                                    {
                                        ints.Add((stringsSplite[0], i, stringsSplite[2]));
                                    }
                                }
                        }
                        //if (item.Contains("DWARF Debugging Information Entries in Section"))
                        //{
                        //    falg1 = true;
                        //}
                    }
                    #region MyRegion

                    for (int i = 0; i < strings.Count; i++)
                    {

                        var item = strings[i];
                        if (item.Contains("00000da0"))
                        {

                        }
                        if (falg)
                        {
                            //listStrng.Add(item);
                            var stringsSplite = item.Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();
                 
                            if (stringsSplite.Count >= 0&& stringsSplite.Count>=3)
                            {
                                if (stringsSplite[2].ToString().Contains("DW_TAG_pointer_type"))
                                {

                                    var findIndex = ints.FindIndex(o => o.Item1 == stringsSplite[0] && o.Item2 == i);
                                    if (findIndex != -1)
                                    {

                                        var next = findIndex + 1;
                                        if (next != ints.Count) //不是最后一个参数
                                        {
                                            var itemFind = ints[next];
                                            var templistStrings = Enumerable.Range(ints[findIndex].Item2, ints[next].Item2 - ints[findIndex].Item2).Select(o => strings[o]).ToList();
                                            if (templistStrings.Any())
                                            {
                                                DW_TAG_pointer_type val = new DW_TAG_pointer_type();
                                                for (global::System.Int32 j = 0; j < templistStrings.Count; j++)
                                                {
                                                    var st = templistStrings[j];
                                                    if (!func(st)) continue;

                                                    var stItems = st.Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();
                                                    var strings_val = stItems[stItems.Count - 1].Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();//最后一个参数的最后一个
                                                    if (stItems.Contains("DW_AT_type"))
                                                    {
                                                        val.DW_AT_type = strings_val[strings_val.Count - 1];
                                                    }
                                                    if (stItems.Contains("DW_AT_name") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_name = strings_val[strings_val.Count - 1];
                                                    }
                                                }
                                                val.line = ints[findIndex].Item1;//获取行号
                                                DW_TAG_pointer_types.Add(val);
                                            }
                                        };

                                    }
                                }
                                if (stringsSplite[2].ToString().Contains("DW_TAG_base_type"))
                                {

                                    var findIndex = ints.FindIndex(o => o.Item1 == stringsSplite[0] && o.Item2 == i);
                                    if (findIndex != -1)
                                    {

                                        var next = findIndex + 1;
                                        if (next != ints.Count) //不是最后一个参数
                                        {
                                            var itemFind = ints[next];
                                            var templistStrings = Enumerable.Range(ints[findIndex].Item2, ints[next].Item2 - ints[findIndex].Item2).Select(o => strings[o]).ToList();
                                            if (templistStrings.Any())
                                            {
                                                DW_TAG_base_type val = new DW_TAG_base_type();
                                                for (global::System.Int32 j = 0; j < templistStrings.Count; j++)
                                                {
                                                    var st = templistStrings[j];
                                                    if (!func(st)) continue;
                                                    var stItems = st.Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();
                                                    var strings_val = stItems[stItems.Count - 1].Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();//最后一个参数的最后一个
                                                    if (stItems.Contains("DW_AT_byte_size"))
                                                    {
                                                        val.DW_AT_byte_size = strings_val[strings_val.Count - 1];
                                                    }
                                                    if (stItems.Contains("DW_AT_name") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_name = strings_val[strings_val.Count - 1];
                                                    }
                                                }
                                                val.line = ints[findIndex].Item1;//获取行号
                                                DW_TAG_base_types.Add(val);

                                            }


                                        };

                                    }
                                }
                                if (stringsSplite[2].ToString().Contains("DW_TAG_typedef") || stringsSplite[2].ToString().Contains("DW_TAG_volatile_type") || stringsSplite[2].ToString().Contains("DW_TAG_TI_far_type"))
                                {

                                    var findIndex = ints.FindIndex(o => o.Item1 == stringsSplite[0] && o.Item2 == i);
                                    if (findIndex != -1)
                                    {

                                        var next = findIndex + 1;
                                        if (next != ints.Count) //不是最后一个参数
                                        {
                                            var itemFind = ints[next];
                                            var templistStrings = Enumerable.Range(ints[findIndex].Item2, ints[next].Item2 - ints[findIndex].Item2).Select(o => strings[o]).ToList();
                                            if (templistStrings.Any())
                                            {
                                                DW_TAG_typedef val = new DW_TAG_typedef();
                                                for (global::System.Int32 j = 0; j < templistStrings.Count; j++)
                                                {


                                                    var st = templistStrings[j];
                                                    if (!func(st)) continue;

                                                    var stItems = st.Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();
                                                    var strings_val = stItems[stItems.Count - 1].Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();//最后一个参数的最后一个
                                                    if (stItems.Contains("DW_AT_name") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_name = strings_val[strings_val.Count - 1];
                                                    }
                                                    if (stItems.Contains("DW_AT_type"))
                                                    {
                                                        val.DW_AT_type = strings_val[strings_val.Count - 1];
                                                    }

                                                }
                                                val.line = ints[findIndex].Item1;//获取行号
                                                DW_TAG_typedefs.Add(val);

                                            }


                                        };

                                    }
                                }
                                if (stringsSplite[2].ToString().Contains("DW_TAG_array_type"))
                                {

                                    var findIndex = ints.FindIndex(o => o.Item1 == stringsSplite[0] && o.Item2 == i);
                                    if (findIndex != -1)
                                    {

                                        var next = findIndex + 1;
                                        if (next != ints.Count) //不是最后一个参数
                                        {
                                            var itemFind = ints[next];
                                            var templistStrings = Enumerable.Range(ints[findIndex].Item2, ints[next].Item2 - ints[findIndex].Item2).Select(o => strings[o]).ToList();
                                            if (templistStrings.Any())
                                            {
                                                DW_TAG_array_type val = new DW_TAG_array_type();
                                                for (global::System.Int32 j = 0; j < templistStrings.Count; j++)
                                                {
                                                    var st = templistStrings[j];
                                                    if (!func(st)) continue;
                                                    var stItems = st.Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();
                                                    var strings_val = stItems[stItems.Count - 1].Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();//最后一个参数的最后一个
                                                    if (stItems.Contains("DW_AT_name") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_name = strings_val[strings_val.Count - 1];
                                                    }
                                                    if (stItems.Contains("DW_AT_byte_size") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_byte_size = strings_val[strings_val.Count - 1];
                                                    }
                                                    if (stItems.Contains("DW_AT_type"))
                                                    {
                                                        val.DW_AT_type = strings_val[strings_val.Count - 1];
                                                    }

                                                }
                                                val.line = ints[findIndex].Item1;//获取行号
                                                DW_TAG_array_types.Add(val);
                                            }
                                        };

                                    }
                                }
                                if (stringsSplite[2].ToString().Contains("DW_TAG_variable"))
                                {

                                    var findIndex = ints.FindIndex(o => o.Item1 == stringsSplite[0] && o.Item2 == i);
                                    if (findIndex != -1)
                                    {

                                        var next = findIndex + 1;
                                        if (next != ints.Count) //不是最后一个参数
                                        {
                                            var itemFind = ints[next];
                                            var templistStrings = Enumerable.Range(ints[findIndex].Item2, ints[next].Item2 - ints[findIndex].Item2).Select(o => strings[o]).ToList();
                                            if (templistStrings.Any())
                                            {
                                                DW_TAG_variable val = new DW_TAG_variable();
                                                for (global::System.Int32 j = 0; j < templistStrings.Count; j++)
                                                {
                                                    var st = templistStrings[j];

                                                    if (st.Contains("g_scopeFormat"))
                                                    {

                                                    }
                                                    if (!func(st)) continue;
                                                    var stItems = st.Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();
                                                    var strings_val = stItems[stItems.Count - 1].Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();//最后一个参数的最后一个
                                                    if (stItems.Contains("DW_AT_name") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_name = strings_val[strings_val.Count - 1];
                                                    }
                                                    if (stItems.Contains("DW_AT_TI_symbol_name") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_TI_symbol_name = strings_val[strings_val.Count - 1];
                                                    }
                                                    if (stItems.Contains("DW_AT_type"))
                                                    {
                                                        val.DW_AT_type = strings_val[strings_val.Count - 1];
                                                    }

                                                }
                                                val.line = ints[findIndex].Item1;//获取行号
                                                dW_TAG_Variables.Add(val);

                                            }


                                        };

                                    }
                                }
                                if (stringsSplite[2].ToString().Contains("DW_TAG_structure_type"))
                                {

                                    var findIndex = ints.FindIndex(o => o.Item1 == stringsSplite[0] && o.Item2 == i);
                                    if (findIndex != -1)
                                    {

                                        var next = findIndex + 1;
                                        if (next != ints.Count) //不是最后一个参数
                                        {
                                            var itemFind = ints[next];
                                            var templistStrings = Enumerable.Range(ints[findIndex].Item2, ints[next].Item2 - ints[findIndex].Item2).Select(o => strings[o]).ToList();


                                            bool f = false;
                                            DW_TAG_member dW_TAG_Member = null;

                                            List<(string, int, string)> DW_TAG_member_ints = new List<(string, int, string)>();
                                            if (templistStrings.Any())
                                            {
                                                DW_TAG_structure_type val = new DW_TAG_structure_type();
                                                for (global::System.Int32 j = 0; j < templistStrings.Count; j++)
                                                {
                                                    var st = templistStrings[j];
                                                    if (!func(st)) continue;
                                                    var stItems = st.Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();
                                                    var strings_val = stItems[stItems.Count - 1].Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();//最后一个参数的最后一个
                                                    if (stItems.Contains("DW_AT_name") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_name = strings_val[strings_val.Count - 1];
                                                    }
                                                    if (stItems.Contains("DW_AT_byte_size") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_byte_size = strings_val[strings_val.Count - 1];
                                                    }

                                                    if (st.Contains("DW_TAG_member"))
                                                    {
                                                        dW_TAG_Member = new DW_TAG_member();
                                                        val.List_DW_TAG_member.Add(dW_TAG_Member); //创建
                                                        val.line = templistStrings[0];
                                                        f = true;
                                                    }
                                                    if (f)
                                                    {
                                                        if (stItems.Contains("DW_AT_name"))
                                                        {
                                                            dW_TAG_Member.DW_AT_name = strings_val[strings_val.Count - 1];
                                                        }

                                                        if (stItems.Contains("DW_AT_TI_symbol_name"))
                                                        {
                                                            dW_TAG_Member.DW_AT_TI_symbol_name = strings_val[strings_val.Count - 1];
                                                        }
                                                        if (stItems.Contains("DW_AT_data_member_location"))
                                                        {
                                                            dW_TAG_Member.DW_AT_data_member_location = strings_val[strings_val.Count - 1];
                                                        }
                                                        if (stItems.Contains("DW_AT_bit_size"))
                                                        {
                                                            dW_TAG_Member.DW_AT_bit_size = strings_val[strings_val.Count - 1];
                                                        }
                                                        if (stItems.Contains("DW_AT_type"))
                                                        {
                                                            dW_TAG_Member.DW_AT_type = strings_val[strings_val.Count - 1];
                                                        }
                                                    }
                                                }
                                                val.line = ints[findIndex].Item1;//获取行号
                                                DW_TAG_structure_types.Add(val);

                                            }


                                        };

                                    }
                                }
                                if (stringsSplite[2].ToString().Contains("DW_TAG_enumeration_type"))
                                {
                                    var findIndex = ints.FindIndex(o => o.Item1 == stringsSplite[0] && o.Item2 == i);
                                    if (findIndex != -1)
                                    {
                                        var next = findIndex + 1;
                                        if (next != ints.Count) //不是最后一个参数
                                        {
                                            var itemFind = ints[next];
                                            var templistStrings = Enumerable.Range(ints[findIndex].Item2, ints[next].Item2 - ints[findIndex].Item2).Select(o => strings[o]).ToList();


                                            bool f = false;
                                            DW_TAG_enumerator dW_TAG_Member = null;

                                            List<(string, int, string)> DW_TAG_member_ints = new List<(string, int, string)>();
                                            if (templistStrings.Any())
                                            {
                                                DW_TAG_enumeration_type val = new DW_TAG_enumeration_type();
                                                for (global::System.Int32 j = 0; j < templistStrings.Count; j++)
                                                {
                                                    var st = templistStrings[j];
                                                    if (!func(st)) continue;
                                                    var stItems = st.Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();
                                                    var strings_val = stItems[stItems.Count - 1].Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();//最后一个参数的最后一个
                                                    if (stItems.Contains("DW_AT_name") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_name = strings_val[strings_val.Count - 1];
                                                    }
                                                    if (stItems.Contains("DW_AT_byte_size") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_byte_size = strings_val[strings_val.Count - 1];
                                                    }

                                                    if (st.Contains("DW_TAG_enumerator"))
                                                    {
                                                        dW_TAG_Member = new DW_TAG_enumerator();
                                                        val.ListDW_TAG_enumerator.Add(dW_TAG_Member); //创建
                                                        val.line = templistStrings[0];
                                                        f = true;
                                                    }
                                                    if (f)
                                                    {
                                                        if (stItems.Contains("DW_AT_name"))
                                                        {
                                                            dW_TAG_Member.DW_AT_name = strings_val[strings_val.Count - 1];
                                                        }
                                                        if (stItems.Contains("DW_AT_TI_symbol_name"))
                                                        {
                                                            dW_TAG_Member.DW_AT_TI_symbol_name = strings_val[strings_val.Count - 1];
                                                        }
                                                        if (stItems.Contains("DW_AT_const_value"))
                                                        {
                                                            dW_TAG_Member.DW_AT_const_value = strings_val[strings_val.Count - 1];
                                                        }
                                                        if (stItems.Contains("DW_AT_type"))
                                                        {
                                                            dW_TAG_Member.DW_AT_type = strings_val[strings_val.Count - 1];
                                                        }
                                                    }
                                                }
                                                val.line = ints[findIndex].Item1;//获取行号
                                                DW_TAG_enumeration_types.Add(val);

                                            }


                                        };

                                    }
                                }
                                if (stringsSplite[2].ToString().Contains("DW_TAG_union_type"))
                                {

                                    var findIndex = ints.FindIndex(o => o.Item1 == stringsSplite[0] && o.Item2 == i);
                                    if (findIndex != -1)
                                    {

                                        var next = findIndex + 1;
                                        if (next != ints.Count) //不是最后一个参数
                                        {
                                            var itemFind = ints[next];
                                            var templistStrings = Enumerable.Range(ints[findIndex].Item2, ints[next].Item2 - ints[findIndex].Item2).Select(o => strings[o]).ToList();


                                            bool f = false;
                                            DW_TAG_member dW_TAG_Member = null;

                                            List<(string, int, string)> DW_TAG_member_ints = new List<(string, int, string)>();
                                            if (templistStrings.Any())
                                            {
                                                DW_TAG_union_type val = new DW_TAG_union_type();
                                                for (global::System.Int32 j = 0; j < templistStrings.Count; j++)
                                                {
                                                    var st = templistStrings[j];
                                                    if (!func(st)) continue;
                                                    var stItems = st.Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();
                                                    var strings_val = stItems[stItems.Count - 1].Split(' ').ToList().Where(o => !string.IsNullOrEmpty(o)).ToList();//最后一个参数的最后一个
                                                    if (stItems.Contains("DW_AT_name") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_name = strings_val[strings_val.Count - 1];
                                                    }
                                                    if (stItems.Contains("DW_AT_byte_size") && stItems.Count == 3)
                                                    {
                                                        val.DW_AT_byte_size = strings_val[strings_val.Count - 1];
                                                    }

                                                    if (st.Contains("DW_TAG_member"))
                                                    {
                                                        dW_TAG_Member = new DW_TAG_member();
                                                        val.List_DW_TAG_member.Add(dW_TAG_Member); //创建
                                                        val.line = templistStrings[0];
                                                        f = true;
                                                    }
                                                    if (f)
                                                    {
                                                        if (stItems.Contains("DW_AT_name"))
                                                        {
                                                            dW_TAG_Member.DW_AT_name = strings_val[strings_val.Count - 1];
                                                        }

                                                        if (stItems.Contains("DW_AT_TI_symbol_name"))
                                                        {
                                                            dW_TAG_Member.DW_AT_TI_symbol_name = strings_val[strings_val.Count - 1];
                                                        }
                                                        if (stItems.Contains("DW_AT_data_member_location"))
                                                        {
                                                            dW_TAG_Member.DW_AT_data_member_location = strings_val[strings_val.Count - 1];
                                                        }
                                                        if (stItems.Contains("DW_AT_bit_size"))
                                                        {
                                                            dW_TAG_Member.DW_AT_bit_size = strings_val[strings_val.Count - 1];
                                                        }
                                                        if (stItems.Contains("DW_AT_type"))
                                                        {
                                                            dW_TAG_Member.DW_AT_type = strings_val[strings_val.Count - 1];
                                                        }
                                                    }
                                                }
                                                val.line = ints[findIndex].Item1;//获取行号
                                                DW_TAG_union_types.Add(val);

                                            }


                                        };

                                    }
                                }
                            }

                        }
                        if (item.Contains("DWARF Debugging Information Entries in Section"))
                        {
                            falg = true;
                        }
                    }
                    #endregion
                    Console.WriteLine("");
                }
            }
        }

        List<DW_TAG_variable> dW_TAG_Variables = new List<DW_TAG_variable>();
        List<DW_TAG_structure_type> DW_TAG_structure_types = new List<DW_TAG_structure_type>();
        List<DW_TAG_union_type> DW_TAG_union_types = new List<DW_TAG_union_type>();
        List<DW_TAG_array_type> DW_TAG_array_types = new List<DW_TAG_array_type>();
        List<DW_TAG_typedef> DW_TAG_typedefs = new List<DW_TAG_typedef>();
        List<DW_TAG_base_type> DW_TAG_base_types = new List<DW_TAG_base_type>();
        List<DW_TAG_pointer_type> DW_TAG_pointer_types = new List<DW_TAG_pointer_type>();
        List<DW_TAG_enumeration_type> DW_TAG_enumeration_types = new List<DW_TAG_enumeration_type>();
        List<(string, string)> valuesTotal = new List<(string, string)>();
        List<string> listname = new List<string>();
        string fileSourse = string.Empty;
        InitialData initialData1 = null;
        List<ulong> listAddressData = new List<ulong>();
        int count = 0;

        List<string> finAdd(string var_name)
        {

            List<string> stringsParas = new List<string>();
            listname.Clear();
            listname = var_name.Split('.').ToList();
            var dt = initialData1.Total_coffSymbolModels.FirstOrDefault(o => o.Name == "_" + listname[0].Split('[')[0]);
            if (dt != null)
            {
                var first = Convert.ToUInt64(dt.Address.Replace("0x", ""), 16); //首地址
                Console.WriteLine($"{listname[0].Split('[')[0]}变量====>起始地址为:{first}");
                var dhex2 = Convert.ToString(first.ToString("X2"));
                Console.WriteLine($"{listname[0].Split('[')[0]}变量====>起始地址为:{dhex2}");
                listAddressData.Clear();
                listAddressData.Add(first);
                if (listname.Count == 1 && !(listname[0].Contains("[") && listname[0].Contains("]"))) //直接返回变量地址
                {
                    stringsParas.Add($"{listname[0].Split('[')[0]}:" + listAddressData.Aggregate((i, o) => { return i + o; }).ToString("X2"));
                    //Console.WriteLine($"当前计算地址为:{listAddressData}");
                }
                else
                {
                    count = 0;
                    var name = listname[0].Split('[')[0];
                    var du = dW_TAG_Variables.First(o => o.DW_AT_name == name);
                    if (du != null)
                    {
                        if (du.DW_AT_type != null)
                        {
                            var type = du.DW_AT_type.Replace("0x", "").PadLeft(8, '0');
                            var d = valuesTotal.First(o => o.Item1.Equals(type));
                            var typeDatastring = d.Item2;
                            count++;
                            Func(listname[0], count, d); //返回地址

                            //foreach (var item in listAddressData)
                            //{
                            //    Console.WriteLine(item);
                            //}
                            Console.WriteLine($"{var_name}====>当前计算地址为:{listAddressData.Aggregate((i, o) => { return i + o; })} ");
                            var dhex = Convert.ToString(listAddressData.Aggregate((i, o) => { return i + o; }).ToString("X2"));
                            Console.WriteLine($"{var_name}====>当前计算地址为:0x{dhex} ");

                            stringsParas.Add($"{var_name}:" +listAddressData.Aggregate((i, o) => { return i + o; }).ToString("X2"));
                        }
                    }


                }


            }

            return stringsParas;
        }

        List<ulong> Func(string datastr, int index, (string, string) die)
        {
            var name = datastr.Split('[')[0];
            string Sec = listname.ElementAtOrDefault(index); //下一级成员
            var typeDatastring = die.Item2;
            if (typeDatastring.Contains("DW_TAG_typedef") || typeDatastring.Contains("DW_TAG_TI_far_type") || typeDatastring.Contains("DW_TAG_volatile_type"))
            {
                var typedef = DW_TAG_typedefs.FirstOrDefault(o => o.DW_AT_type != null && !string.IsNullOrEmpty(o.DW_AT_type) && o.line == die.Item1);

                if (typedef != null) //找到DW_TAG_typedef
                {
                    var dSt = valuesTotal.First(o => o.Item1.Equals(typedef.DW_AT_type.Replace("0x", "").PadLeft(8, '0')));//查找offset总表
                    var typestring = dSt.Item2;
                    DataTagName(datastr, dSt, Sec);
                }
            }
            else if ((datastr.Contains("[") && datastr.Contains("]"))) //判断是一个数组
            {
                if (typeDatastring.Contains("DW_TAG_array_type"))
                {
                    var DW_TAG_array_types_item = DW_TAG_array_types.First(o => o.line != null && !string.IsNullOrEmpty(o.line) && o.line == die.Item1);//在数组中查找
                    var men_name = datastr.Split('[')[0];
                    var datMen = DW_TAG_array_types_item;
                    if (datMen != null && !string.IsNullOrEmpty(men_name) && !string.IsNullOrEmpty($"{datMen.DW_AT_type.Replace("0x", "").PadLeft(8, '0')}"))
                    {
                        var datMen_type = valuesTotal.First(o => o.Item1.Equals(datMen.DW_AT_type.Replace("0x", "").PadLeft(8, '0'))); //查找成员类型
                        {
                            var d2 = valuesTotal.First(o => o.Item1.Equals(datMen_type.Item1));//查找类型后再总表中查找
                            var typeDatastring2 = d2.Item2;
                            if (typeDatastring2.Contains("DW_TAG_typedef") || typeDatastring2.Contains("DW_TAG_volatile_type") || typeDatastring2.Contains("DW_TAG_TI_far_type")) //在类型表中查找
                            {
                                var typedef3 = DW_TAG_typedefs.FirstOrDefault(o => o.DW_AT_type != null && !string.IsNullOrEmpty(o.DW_AT_type) && o.line == d2.Item1);
                                if (typedef3 != null)
                                {
                                    var DW_TAG_typedef_Men = valuesTotal.First(o => o.Item1.Equals(typedef3.DW_AT_type.Replace("0x", "").PadLeft(8, '0'))); //在总表中查找
                                    if (DW_TAG_typedef_Men.Item2.Contains("DW_TAG_base_type"))
                                    {
                                        var DW_TAG_base_type_obj = DW_TAG_base_types.FirstOrDefault(o => o.line == DW_TAG_typedef_Men.Item1);
                                        if (DW_TAG_base_type_obj != null)
                                        {
                                            if (datastr.Contains("["))
                                            {
                                                var match = Regex.Matches(datastr, @"(?<=\[).*?(?=\])");//获取<>内的内容(为修改后的名称)
                                                if (match.Count > 1)
                                                {
                                                    var list = match.Cast<ulong>().Select(uu => ulong.Parse(uu.ToString())).ToList().Aggregate<ulong>((o, Datai) => { return (ulong.Parse(o.ToString())) * ulong.Parse(Datai.ToString()); });

                                                    listAddressData.Add(list * UInt64.Parse(DW_TAG_base_type_obj.DW_AT_byte_size));
                                                }
                                                else if (match.Count == 1)
                                                {
                                                    listAddressData.Add((ulong.Parse(match[0].ToString())) * UInt64.Parse(DW_TAG_base_type_obj.DW_AT_byte_size));
                                                }
                                            }
                                            else
                                            {
                                                Debug.WriteLine("当前结构体变量不存在");
                                            }
                                        }

                                    }
                                    else
                                    {
                                        count++;
                                        Func(Sec, count, DW_TAG_typedef_Men);
                                    }
                                }
                            }

                        }
                    }




                }
            }
            else  //或者结构体具体类型
            {
                DataTagName(datastr, die, Sec);
            }
            return listAddressData;
        }

        public void DataTagName(string datastr, (string, string) die, string Sec)
        {
            var typestring = die.Item2;

            if (typestring.Contains("DW_TAG_structure_type"))
            {
                //在DW_TAG_structure_type中查找 structure
                var typeDW_TAG_structure_type = DW_TAG_structure_types.First(o => o.line != null && !string.IsNullOrEmpty(o.line) && o.line == die.Item1);
                if (datastr.Contains("["))
                {
                    var match = Regex.Matches(datastr, @"(?<=\[).*?(?=\])");//获取<>内的内容(为修改后的名称)@"(?i)(?<=\[)(.*)(?=\])"
                    if (match.Count > 1)
                    {
                        var list = match.Cast<ulong>().Select(uu => ulong.Parse(uu.ToString())).ToList().Aggregate<ulong>((o, Datai) => { return ulong.Parse(o.ToString()) * ulong.Parse(Datai.ToString()); });
                        listAddressData.Add(list * UInt64.Parse(typeDW_TAG_structure_type.DW_AT_byte_size));
                    }
                    else if (match.Count == 1)
                    {
                        Console.WriteLine($"{listAddressData}");
                        listAddressData.Add(ulong.Parse(match[0].ToString()) * UInt64.Parse(typeDW_TAG_structure_type.DW_AT_byte_size)); //获取结构体偏移地址
                        Console.WriteLine($"{listAddressData}={ulong.Parse(match[0].ToString()) * UInt64.Parse(typeDW_TAG_structure_type.DW_AT_byte_size)}");

                    }
                }

                if (typeDW_TAG_structure_type != null && !string.IsNullOrEmpty(Sec)) //判断下一级是否循环
                {
                    var men_name = Sec.Split('[')[0];
                    var datMen = typeDW_TAG_structure_type.List_DW_TAG_member.FirstOrDefault(o => o.DW_AT_name == men_name); //判断下一个成员是否在结构体里面(查找到成员)
                    if (datMen != null && !string.IsNullOrEmpty(men_name))
                    {

                        listAddressData.Add(ulong.Parse(datMen.DW_AT_data_member_location)); //获取偏移
                        Console.WriteLine($"成员:{datMen.DW_AT_name},偏移{datMen.DW_AT_data_member_location}");
                        var datMen_type = valuesTotal.First(o => o.Item1.Equals(datMen.DW_AT_type.Replace("0x", "").PadLeft(8, '0'))); //查找Offset
                        {
                            var d2 = valuesTotal.First(o => o.Item1.Equals(datMen_type.Item1));//查找类型后再总表中查找
                            var typeDatastring2 = d2.Item2;
                            if (typeDatastring2.Contains("DW_TAG_typedef") || typeDatastring2.Contains("DW_TAG_volatile_type") || typeDatastring2.Contains("DW_TAG_TI_far_type")) //查找类型后再总表中查找  
                            {
                                var typedef2 = DW_TAG_typedefs.First(o => o.DW_AT_type != null && !string.IsNullOrEmpty(o.DW_AT_type) && o.line == d2.Item1);
                                if (typedef2 != null)
                                {
                                    var DW_TAG_typedef_Men = valuesTotal.First(o => o.Item1.Equals(typedef2.DW_AT_type.Replace("0x", "").PadLeft(8, '0'))); //查找类型后又在总表中查找

                                    if (DW_TAG_typedef_Men.Item2.Contains("DW_TAG_base_type"))
                                    {
                                        var DW_TAG_base_type_obj = DW_TAG_base_types.FirstOrDefault(o => o.line == DW_TAG_typedef_Men.Item1);
                                        if (DW_TAG_base_type_obj != null)
                                        {
                                            if (Sec.Contains("["))
                                            {
                                                var match = Regex.Matches(Sec, @"(?<=[).*?(?=])");//获取<>内的内容(为修改后的名称)
                                                if (match.Count > 1)
                                                {
                                                    var list = match.Cast<ulong>().Select(uu => ulong.Parse(uu.ToString())).ToList().Aggregate<ulong>((o, Datai) => { return (ulong.Parse(o.ToString())) * ulong.Parse(Datai.ToString()); });

                                                    listAddressData.Add(list * UInt64.Parse(DW_TAG_base_type_obj.DW_AT_byte_size));
                                                }
                                                else if (match.Count == 1)
                                                {
                                                    listAddressData.Add((ulong.Parse(match[0].ToString())) * UInt64.Parse(DW_TAG_base_type_obj.DW_AT_byte_size));
                                                }
                                            }
                                        }

                                    }
                                    else if (DW_TAG_typedef_Men.Item2.Contains("DW_TAG_array_type"))
                                    {
                                        count++;
                                        Func(Sec, count, d2);
                                    }
                                    else if (DW_TAG_typedef_Men.Item2.Contains("DW_TAG_structure_type"))
                                    {
                                        count++;
                                        Func(Sec, count, d2);
                                    }
                                }
                            }
                            else
                            {
                                count++;
                                Func(Sec, count, d2);
                            }
                        }
                    }
                    else
                    {
                        Debug.WriteLine("当前结构体变量不存在");
                    }
                }
            }
            else if (typestring.Contains("DW_TAG_union_type"))
            {
                //在DW_TAG_structure_type中查找 structure
                var type_DW_TAG_union_types = DW_TAG_union_types.First(o => o.line != null && !string.IsNullOrEmpty(o.line) && o.line == die.Item1);
                if (datastr.Contains("["))
                {
                    var match = Regex.Matches(datastr, @"(?<=\[).*?(?=\])");//获取<>内的内容(为修改后的名称)@"(?i)(?<=\[)(.*)(?=\])"
                    if (match.Count > 1)
                    {
                        var list = match.Cast<ulong>().Select(uu => ulong.Parse(uu.ToString())).ToList().Aggregate<ulong>((o, Datai) => { return ulong.Parse(o.ToString()) * ulong.Parse(Datai.ToString()); });
                        listAddressData.Add(list * UInt64.Parse(type_DW_TAG_union_types.DW_AT_byte_size));
                    }
                    else if (match.Count == 1)
                    {
                        Console.WriteLine($"{listAddressData}");
                        listAddressData.Add(ulong.Parse(match[0].ToString()) * UInt64.Parse(type_DW_TAG_union_types.DW_AT_byte_size)); //获取结构体偏移地址
                        Console.WriteLine($"{listAddressData}={ulong.Parse(match[0].ToString()) * UInt64.Parse(type_DW_TAG_union_types.DW_AT_byte_size)}");

                    }
                }

                if (type_DW_TAG_union_types != null && !string.IsNullOrEmpty(Sec)) //判断下一级是否循环
                {
                    var men_name = Sec.Split('[')[0];
                    var datMen = type_DW_TAG_union_types.List_DW_TAG_member.FirstOrDefault(o => o.DW_AT_name == men_name); //判断下一个成员是否在结构体里面(查找到成员)
                    if (datMen != null && !string.IsNullOrEmpty(men_name))
                    {
                        listAddressData.Add(ulong.Parse(datMen.DW_AT_data_member_location)); //获取偏移
                        Console.WriteLine($"成员:{datMen.DW_AT_name},偏移{datMen.DW_AT_data_member_location}");

                        var datMen_type = valuesTotal.First(o => o.Item1.Equals(datMen.DW_AT_type.Replace("0x", "").PadLeft(8, '0'))); //查找Offset
                        {
                            var d2 = valuesTotal.First(o => o.Item1.Equals(datMen_type.Item1));//查找类型后再总表中查找
                            var typeDatastring2 = d2.Item2;
                            if (typeDatastring2.Contains("DW_TAG_typedef") || typeDatastring2.Contains("DW_TAG_volatile_type") || typeDatastring2.Contains("DW_TAG_TI_far_type")) //查找类型后再总表中查找  
                            {
                                var typedef2 = DW_TAG_typedefs.First(o => o.DW_AT_type != null && !string.IsNullOrEmpty(o.DW_AT_type) && o.line == d2.Item1);
                                if (typedef2 != null)
                                {
                                    var DW_TAG_typedef_Men = valuesTotal.First(o => o.Item1.Equals(typedef2.DW_AT_type.Replace("0x", "").PadLeft(8, '0'))); //查找类型后又在总表中查找

                                    if (DW_TAG_typedef_Men.Item2.Contains("DW_TAG_base_type"))
                                    {
                                        var DW_TAG_base_type_obj = DW_TAG_base_types.FirstOrDefault(o => o.line == DW_TAG_typedef_Men.Item1);
                                        if (DW_TAG_base_type_obj != null)
                                        {
                                            if (Sec.Contains("["))
                                            {
                                                var match = Regex.Matches(Sec, @"(?<=[).*?(?=])");//获取<>内的内容(为修改后的名称)
                                                if (match.Count > 1)
                                                {
                                                    var list = match.Cast<ulong>().Select(uu => ulong.Parse(uu.ToString())).ToList().Aggregate<ulong>((o, Datai) => { return (ulong.Parse(o.ToString())) * ulong.Parse(Datai.ToString()); });

                                                    listAddressData.Add(list * UInt64.Parse(DW_TAG_base_type_obj.DW_AT_byte_size));
                                                }
                                                else if (match.Count == 1)
                                                {
                                                    listAddressData.Add((ulong.Parse(match[0].ToString())) * UInt64.Parse(DW_TAG_base_type_obj.DW_AT_byte_size));
                                                }
                                            }
                                        }

                                    }
                                    else if (DW_TAG_typedef_Men.Item2.Contains("DW_TAG_array_type"))
                                    {
                                        count++;
                                        Func(Sec, count, d2);
                                    }
                                    else if (DW_TAG_typedef_Men.Item2.Contains("DW_TAG_structure_type"))
                                    {
                                        count++;
                                        Func(Sec, count, d2);
                                    }
                                }
                            }
                            else
                            {
                                count++;
                                Func(Sec, count, d2);
                            }
                        }
                    }
                    else
                    {
                      //  Debug.WriteLine("当前结构体变量不存在");
                    }
                }
            }
            else if (typestring.Contains("DW_TAG_array_type"))
            {
                var DW_TAG_array_types_item = DW_TAG_array_types.First(o => o.line != null && !string.IsNullOrEmpty(o.line) && o.line == die.Item1);//在数组中查找
                var men_name = datastr.Split('[')[0];
                var datMen = DW_TAG_array_types_item;
                if (datMen != null && !string.IsNullOrEmpty(men_name) && !string.IsNullOrEmpty($"{datMen.DW_AT_type}"))
                {

                    var datMen_type = valuesTotal.First(o => o.Item1.Equals(datMen.DW_AT_type)); //查找成员类型(有些问题)
                    {

                        var d2 = valuesTotal.First(o => o.Item1.Equals(datMen_type.Item1));//查找类型后再总表中查找
                        var typeDatastring2 = d2.Item2;
                        if (typeDatastring2.Contains("DW_TAG_typedef") || typeDatastring2.Contains("DW_TAG_volatile_type") || typeDatastring2.Contains("DW_TAG_TI_far_type")) //查找类型后再总表中查找
                        {
                            var typedef3 = DW_TAG_typedefs.First(o => o.DW_AT_type != null && !string.IsNullOrEmpty(o.DW_AT_type) && o.line == d2.Item1);
                            if (typedef3 != null)
                            {
                                var DW_TAG_typedef_Men = valuesTotal.First(o => o.Item1.Equals(typedef3.DW_AT_type)); //查找类型后又在总表中查找
                                if (DW_TAG_typedef_Men.Item2.Contains("DW_TAG_base_type"))
                                {
                                    var DW_TAG_base_type_obj = DW_TAG_base_types.First(o => o.line == DW_TAG_typedef_Men.Item1);
                                    if (DW_TAG_base_type_obj != null)
                                    {
                                        if (datastr.Contains("["))
                                        {
                                            var match = Regex.Matches(Sec, @"(?<=[).*?(?=])");//获取<>内的内容(为修改后的名称)
                                            if (match.Count > 1)
                                            {
                                                var list = match.Cast<ulong>().Select(uu => ulong.Parse(uu.ToString())).ToList().Aggregate<ulong>((o, Datai) => { return (ulong.Parse(o.ToString())) * ulong.Parse(Datai.ToString()); });

                                                listAddressData.Add(list * UInt64.Parse(DW_TAG_base_type_obj.DW_AT_byte_size));
                                            }
                                            else if (match.Count == 1)
                                            {
                                                listAddressData.Add((ulong.Parse(match[0].ToString())) * UInt64.Parse(DW_TAG_base_type_obj.DW_AT_byte_size));
                                            }
                                        }
                                        //listAddressData += ulong.Parse(DW_TAG_base_type_obj.lo);
                                    }

                                }
                                else
                                {
                                    count++;
                                    Func(datastr, count, DW_TAG_typedef_Men);
                                }

                            }
                        }

                    }
                }
            }
            else if (typestring.Contains("DW_TAG_enumeration_type"))
            {
                //在DW_TAG_structure_type中查找 structure
                var typeDW_TAG_Enumeratetype = DW_TAG_enumeration_types.First(o => o.line != null && !string.IsNullOrEmpty(o.line) && o.line == die.Item1);
                if (datastr.Contains("["))
                {
                    var match = Regex.Matches(datastr, @"(?<=\[).*?(?=\])");//获取<>内的内容(为修改后的名称)@"(?i)(?<=\[)(.*)(?=\])"
                    if (match.Count > 1)
                    {
                        var list = match.Cast<ulong>().Select(uu => ulong.Parse(uu.ToString())).ToList().Aggregate<ulong>((o, Datai) => { return ulong.Parse(o.ToString()) * ulong.Parse(Datai.ToString()); });
                        listAddressData.Add(list * UInt64.Parse(typeDW_TAG_Enumeratetype.DW_AT_byte_size));
                    }
                    else if (match.Count == 1)
                    {
                        Console.WriteLine($"{listAddressData}");
                        listAddressData.Add(ulong.Parse(match[0].ToString()) * UInt64.Parse(typeDW_TAG_Enumeratetype.DW_AT_byte_size)); //获取结构体偏移地址
                        Console.WriteLine($"{listAddressData}={ulong.Parse(match[0].ToString()) * UInt64.Parse(typeDW_TAG_Enumeratetype.DW_AT_byte_size)}");

                    }
                }

                if (typeDW_TAG_Enumeratetype != null && !string.IsNullOrEmpty(Sec)) //判断下一级是否循环
                {
                    var men_name = Sec.Split('[')[0];
                    var datMen = typeDW_TAG_Enumeratetype.ListDW_TAG_enumerator.FirstOrDefault(o => o.DW_AT_name == men_name); //判断下一个成员是否在结构体里面
                    if (datMen != null && !string.IsNullOrEmpty(men_name))
                    {
                        listAddressData.Add(ulong.Parse(datMen.DW_AT_const_value)); //获取偏移
                        Console.WriteLine($"成员:{datMen.DW_AT_name},偏移{datMen.DW_AT_const_value}");
                        var datMen_type = valuesTotal.First(o => o.Item1.Equals(datMen.DW_AT_type.Replace("0x", "").PadLeft(8, '0'))); //查找Offset
                        {

                            var d2 = valuesTotal.First(o => o.Item1.Equals(datMen_type.Item1));//查找类型后再总表中查找
                            var typeDatastring2 = d2.Item2;
                            if (typeDatastring2.Contains("DW_TAG_typedef") || typeDatastring2.Contains("DW_TAG_volatile_type") || typeDatastring2.Contains("DW_TAG_TI_far_type")) //查找类型后再总表中查找
                            {
                                var typedef2 = DW_TAG_typedefs.First(o => o.DW_AT_type != null && !string.IsNullOrEmpty(o.DW_AT_type) && o.line == d2.Item1);
                                if (typedef2 != null)
                                {
                                    var DW_TAG_typedef_Men = valuesTotal.First(o => o.Item1.Equals(typedef2.DW_AT_type.Replace("0x", "").PadLeft(8, '0'))); //查找类型后又在总表中查找
                                    if (DW_TAG_typedef_Men.Item2.Contains("DW_TAG_base_type"))
                                    {
                                        var DW_TAG_base_type_obj = DW_TAG_base_types.FirstOrDefault(o => o.line == DW_TAG_typedef_Men.Item1);
                                        if (DW_TAG_base_type_obj != null)
                                        {
                                            if (Sec.Contains("["))
                                            {
                                                var match = Regex.Matches(Sec, @"(?<=[).*?(?=])");//获取<>内的内容(为修改后的名称)
                                                if (match.Count > 1)
                                                {
                                                    var list = match.Cast<ulong>().Select(uu => ulong.Parse(uu.ToString())).ToList().Aggregate<ulong>((o, Datai) => { return (ulong.Parse(o.ToString())) * ulong.Parse(Datai.ToString()); });

                                                    listAddressData.Add(list * UInt64.Parse(DW_TAG_base_type_obj.DW_AT_byte_size));
                                                }
                                                else if (match.Count == 1)
                                                {
                                                    listAddressData.Add((ulong.Parse(match[0].ToString())) * UInt64.Parse(DW_TAG_base_type_obj.DW_AT_byte_size));
                                                }
                                            }
                                        }

                                    }
                                    else
                                    {
                                        count++;
                                        Func(datastr, count, DW_TAG_typedef_Men);
                                    }

                                }
                            }

                        }
                    }
                    else
                    {
                        Debug.WriteLine("当前结构体变量不存在");
                    }
                }
            }
            else
            {
                Func(datastr, count, die);//还需要再递归
            }
        }


        public static IEnumerable<string> LoadFilelistString(string FileToRead)
        {
            IEnumerable<string> line = null;
            // Creating enumerable object
            if (File.Exists(FileToRead))
                line = File.ReadLines(FileToRead);
            return line;
        }

        public List<string> CalculateAddressList(List<string> Paranames)
        {

            List<string> listStrings = new List<string>();
            if (fileSourse.EndsWith(".out"))
            {
              var  strings = Paranames;
                for (int i = 0; i < strings.Count; i++)
                {
                    var item = strings[i];
                    var data = finAdd(item);
                    if (data.Count==1)
                    {
                        listStrings.Add(data[0]);
                    }
                }
            }
            else if (fileSourse.EndsWith(".elf"))
            {
                //绝对路径

                var name = string.Join(",", Paranames);
                var re = ParseELF.CallParseELF(fileSourse, name);
                if (re.Item1)
                {
                    foreach (var item in re.Item2)
                    {
                        Console.WriteLine(item);
                    }
                }
            }

            return listStrings;
        }

        public static bool WriteBatFile(string filePath, string fileContent)
        {
            try
            {
                if (File.Exists(filePath))
                    File.Delete(filePath);
                FileStream fs1 = new FileStream(filePath, FileMode.Create, FileAccess.Write);//创建写入文件
                StreamWriter sw = new StreamWriter(fs1, Encoding.GetEncoding("GB2312"));
                sw.WriteLine(fileContent);//开始写入值
                sw.Close();
                fs1.Close();
                return true;
            }
            catch (Exception ex)
            {

                return false;
            }
        }
        /// <summary>
        /// 调用python程序
        /// </summary>
        /// <param name="batContent"></param>
        /// <param name="tiName"></param>
        public static (bool, List<string>) callpython(string batContent)
        {

            bool Rsult = false;
            var mianDir = Path.Combine($"{AppDomain.CurrentDomain.BaseDirectory}", "Parser");//存放调用外部程序的地方
            string batPath = $"{mianDir}\\textCellNameCreateepromData.bat";
            StringBuilder stringBuilder = new StringBuilder();
            //目前固定是CRC32
            stringBuilder.AppendLine(batContent);

            List<string> listLineTure = new List<string>();

            var writeResult = WriteBatFile(batPath, stringBuilder.ToString());//如果存在则清空
            if (writeResult)
            {
                var proc = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName = batPath,
                        WorkingDirectory = mianDir,
                        UseShellExecute = false,
                        CreateNoWindow = true,

                    }
                };
                proc.StartInfo.Verb = "runas";
                proc.StartInfo.RedirectStandardInput = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError = true;
                proc.Start();
                while (!proc.StandardOutput.EndOfStream)
                {
                    string line = proc.StandardOutput.ReadLine();
                    Console.WriteLine(line);
                    if (line.Contains("地址为:"))
                        listLineTure.Add(line);
                }

                while (!proc.StandardError.EndOfStream)
                {
                    string line = proc.StandardError.ReadLine();
                }

                proc.WaitForExit();
                proc.Close();
            }

            if (listLineTure.Count == 3)
            {
                var dataCount = listLineTure.Where(o => o.Contains("地址为:")).Count();
                if (dataCount == 3)
                    Rsult = true;
            }
            return (Rsult, listLineTure);
        }

        /// <summary>
        /// 调用fd6x程序
        /// </summary>
        /// <param name="batContent"></param>
        /// <param name="tiName"></param>
        void callofd6x(string batContent)
        {
            var mianDir = Path.Combine($"{AppDomain.CurrentDomain.BaseDirectory}", "Parser");//存放调用外部程序的地方
            string batPath = $"{mianDir}\\textCellNameCreateepromData.bat";
            StringBuilder stringBuilder = new StringBuilder();
            //目前固定是CRC32
            stringBuilder.AppendLine(batContent);

            var writeResult = WriteBatFile(batPath, stringBuilder.ToString());//如果存在则清空
            if (writeResult)
            {
                var proc = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName = batPath,
                        WorkingDirectory = mianDir,
                        UseShellExecute = false,
                        CreateNoWindow = true,

                    }
                };
                proc.StartInfo.Verb = "runas";
                proc.StartInfo.RedirectStandardInput = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError = true;
                proc.Start();
                while (!proc.StandardOutput.EndOfStream)
                {
                    string line = proc.StandardOutput.ReadLine();
                 //   Debug.WriteLine(line);
                }

                while (!proc.StandardError.EndOfStream)
                {
                    string line = proc.StandardError.ReadLine();
                   // Debug.WriteLine(line);
                }

                proc.WaitForExit();
                proc.Close();
            }
        }
    }
}
